/*
 * @Description: 用户配置管理 - 接口
 * @Author:
 * @Date: 2024-02-02 13:44:51
 * @LastEditors: DHL
 * @LastEditTime: 2024-02-02 13:49:46
 */

import { $get, $post } from '@/utils/http'
import { ContentTypeEnum } from '@/constant/http'
import {
  UserConfigModel,
  UserConfigPageParams,
  UserConfigPageResultModel,
  UserConfigResultModel
} from './model/userConfigModel'

/**
 * 分页查询
 */
export const apiUserConfigSearch = (searchParams: UserConfigPageParams) =>
  $get<UserConfigPageResultModel>({
    url: '/system/twbUserConfig/search',
    params: searchParams
  })

/**
 * 查询合计
 * @param searchParams
 * @returns
 */
export const apiUserConfigSearchSum = (searchParams: UserConfigPageParams) =>
  $get<UserConfigResultModel>({
    url: '/system/twbUserConfig/searchSum',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiUserConfigGetById = (id: string) =>
  $get<UserConfigResultModel>({
    url: '/system/twbUserConfig/getById',
    params: { id: id }
  })

/**
 * 保存/更新信息
 */
export const apiUserConfigSaveOrUpdate = (saveParams: UserConfigModel) =>
  $post<UserConfigResultModel>({
    url: '/system/twbUserConfig/saveOrUpdate',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 删除用户配置
 * @param userId  用户ID，默认当前登录用户
 * @param configType  配置类型（1：表格列配置；2：系统配置）
 * @returns
 */
export const apiUserConfigDeleteByUserIdAndType = (userId: string, configType: string) =>
  $post<UserConfigResultModel>({
    url: '/system/twbUserConfig/deleteByUserIdAndType',
    params: { userId: userId, configType: configType }
  })
